<template>
  <el-dialog
    v-el-drag-dialog
    :title="!dataForm.returnId ? '审核操作' : '审核操作'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="160px">
    <el-form-item label="物流公司" prop="supplierShipId">
      <el-select v-model="dataForm.supplierShipId">
        <el-option 
          v-for="item in dataForm.express"
          :key="item.id"
          :label="item.companyName"
          :value="item.id">
        </el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="供应商寄件物流单号" prop="supplierShipCode">
      <el-input type="input" v-model="dataForm.supplierShipCode" placeholder="供应商寄件物流单号"></el-input>
    </el-form-item>
    <el-form-item label="供应商寄件备注" prop="supplierShipRemark">
      <el-input type="textarea" v-model="dataForm.supplierShipRemark" placeholder="供应商寄件备注"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        goodsInfoList: [],
        dataForm: {
          returnId: 0,
          returnStatus: '',
          goodsCartId: '',
          returnType: '',
          userAuditRemark: '',
          platformAuditRemark: '',
          supplierDeliveryName: '',
          supplierDeliveryIphone: '',
          supplierDeliveryAddress: '',
          supplierDeliveryRemark: '',
          supplierShipCode: '',
          supplierShipId: '',
          supplierShipRemark: '',
          express: []
        },
        dataRule: {}
      }
    },
    methods: {
      init (id, goodsCartId, returnStatus) {
        this.dataForm.returnId = id || 0
        this.dataForm.returnStatus = returnStatus
        this.dataForm.goodsCartId = goodsCartId
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          this.$http({
            url: this.$http.adornUrl('/returnGoods/queryExpress'),
            method: 'post'
          }).then(({data}) => {
            this.dataForm.express = data.data
          })
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl('/returnGoods/shipmentByExchange'),
              method: 'post',
              data: this.$http.adornData({
                'returnId': this.dataForm.returnId,
                'goodsCartId': this.dataForm.goodsCartId,
                'returnStatus': this.dataForm.returnStatus,
                'userAuditRemark': this.dataForm.userAuditRemark,
                'platformAuditRemark': this.dataForm.platformAuditRemark,
                'supplierDeliveryName': this.dataForm.supplierDeliveryName,
                'supplierDeliveryIphone': this.dataForm.supplierDeliveryIphone,
                'supplierDeliveryAddress': this.dataForm.supplierDeliveryAddress,
                'supplierDeliveryRemark': this.dataForm.supplierDeliveryRemark,
                'supplierShipCode': this.dataForm.supplierShipCode,
                'supplierShipId': this.dataForm.supplierShipId,
                'supplierShipRemark': this.dataForm.supplierShipRemark
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
